// Globals
global students	L_BLabil Dmiss_BL Dmale Lage 
global teachers1 DTeachMale  LTeachAge LTeachExper LTeachEduc 
global schools Lenrol LPTR LPLEPassRate LNTeachers 			  			   
// Subtracting the effect
	global doutcomes ""
	use "$dir\DataSCLB", clear
	foreach var in $students $teachers1 $schools {
		reg `var' MT_Program CCT_Program, a(Group_detailed_blind) 
		gen _`var' = `var'
		replace _`var' = `var' - _b[MT_Program] if Study_Arm==2
		replace _`var' = `var' - _b[CCT_Program] if Study_Arm==1
		local lab: variable label `var'
		label var _`var' "`lab'"
		global doutcomes $doutcomes _`var'
	}
	rankbstrp $doutcomes, reps(1000) individuals conditional
	save "$output/Table4.dta", replace		
	
	# delimit ;
			texsave names MT_p25 MT_p25_p50 MT_p50_p75 MT_p75 blank2  CCT_p25 CCT_p25_p50 CCT_p50_p75 CCT_p75 using "$output/T4.tex",
					replace align(lccccccccc) location(H) hlines(8 16) 
					headerlines("& \multicolumn{4}{c}{Full-Cost} & & \multicolumn{4}{c}{Reduced-Cost} \\ 
					\cmidrule{2-5} \cmidrule{7-10}
					& 0-25th Perc. & 25-50th Perc. & 50-75th Perc. & 75-100th Perc. & & 0-25th Perc. & 25-50th Perc. & 50-75th Perc. & 75-100th Perc. \\ 
					\cmidrule{2-5} \cmidrule{7-10}
					& (1) & (2) & (3) & (4) & & (5) & (6) & (7) & (8)")
					marker(tb:rank_preservation) title(\\ Tests of Covariate Balance by Endline Test Score Quartile) 
					size(small) frag nofix nonames   ;
			# delimit cr